package cn.itcast.store.service.serviceImp;

import java.sql.SQLException;

import cn.itcast.store.dao.UserDao;
import cn.itcast.store.dao.daoImp.UserDaoImp;
import cn.itcast.store.domain.Admin;
import cn.itcast.store.domain.User;
import cn.itcast.store.service.UserService;
import cn.itcast.store.utils.MailUtils;

public class UserServiceImp implements UserService {

	@Override
	public void userRegist(User user01) throws SQLException{
		UserDao UserDao =new UserDaoImp();
		//3_调用业务层注册功能
		UserDao.userRegist(user01);
		try {
			//向用户邮箱发送一份激活邮件
			MailUtils.sendMail(user01.getEmail(),user01.getCode());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public User userActive(String code) throws Exception {
		UserDao UserDao =new UserDaoImp();
		return  UserDao.userActive(code);
	}

	@Override
	public void updateUser(User user) throws Exception {
		UserDao UserDao =new UserDaoImp();
		UserDao.updateUser(user);
	}

	@Override
	public User login(User user) throws Exception {
		UserDao UserDao =new UserDaoImp();
		return UserDao.login(user);
	}

	@Override
	public Admin Adminlogin(Admin admin) throws Exception {
		UserDao UserDao =new UserDaoImp();
		return UserDao.Adminlogin(admin);
	}
}
